package com.fx.zmlzml.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fx.zmlzml.entity.PcCase;
import com.fx.zmlzml.mapper.PcCaseMapper;
import com.fx.zmlzml.service.PcCaseService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * 电脑机箱 Service实现类
 * 实现电脑机箱相关的业务逻辑
 */
@Service
public class PcCaseServiceImpl extends ServiceImpl<PcCaseMapper, PcCase> implements PcCaseService {
    
    private static final Logger logger = LoggerFactory.getLogger(PcCaseServiceImpl.class);

    @Override
    public List<PcCase> getListByParams(Integer maxPrice, Integer minPrice) {
        logger.info("查询所有符合条件的电脑机箱列表，查询条件：maxPrice={}, minPrice={}", maxPrice, minPrice);
        List<PcCase> list = baseMapper.getListByParams(maxPrice, minPrice);
        logger.info("机箱总条数：{}", list.size());
        return list;
    }

    @Override
    public boolean save(PcCase entity) {
        logger.info("保存电脑机箱信息，制造商：{}", entity.getManufacturer());
        try {
            boolean result = super.save(entity);
            if (result) {
                logger.debug("保存电脑机箱成功，ID：{}", entity.getId());
            } else {
                logger.warn("保存电脑机箱失败，制造商：{}", entity.getManufacturer());
            }
            return result;
        } catch (Exception e) {
            logger.error("保存电脑机箱异常，制造商：{}", entity.getManufacturer(), e);
            throw e;
        }
    }
    
    @Override
    public boolean updateById(PcCase entity) {
        logger.info("更新电脑机箱信息，ID：{}", entity.getId());
        try {
            boolean result = super.updateById(entity);
            if (result) {
                logger.debug("更新电脑机箱成功，ID：{}", entity.getId());
            } else {
                logger.warn("更新电脑机箱失败，ID：{}", entity.getId());
            }
            return result;
        } catch (Exception e) {
            logger.error("更新电脑机箱异常，ID：{}", entity.getId(), e);
            throw e;
        }
    }
    
    @Override
    public boolean removeById(Serializable id) {
        logger.info("删除电脑机箱，ID：{}", id);
        try {
            boolean result = super.removeById(id);
            if (result) {
                logger.debug("删除电脑机箱成功，ID：{}", id);
            } else {
                logger.warn("删除电脑机箱失败，ID：{}", id);
            }
            return result;
        } catch (Exception e) {
            logger.error("删除电脑机箱异常，ID：{}", id, e);
            throw e;
        }
    }

}